<?php


namespace app\user\controller;


use app\admin\command\Api;
use app\user\model\BannerModel;
use think\Request;

class Banner extends Base
{
    protected $noNeedLogin = '*';
    public function index()
    {
        $data = BannerModel::order('id','DESC')
            ->field('id,image')
            ->select();
        if (!$data) {
            $this->error('暂无数据');
        }
        $this->success('查询成功',[
            'image' => $data
        ]);
    }

//    public function add(Request $request)
//    {
//        $data = input('post.');
////        $validate = new MenuValidate();
////        $result = $validate->scene('register')->check($data);
////        if($result !== true){
////            return error($validate->getError());
////        }
//        //判断是否已经注册
//        $exists = BannerModel::where('image',$data['image'])->find();
//        if($exists){
//            $this->error('该图片已拥有');
//        }
////        $res = verifyEmailCheckCode($data['email'],$data['check_code']);
////        if($res['code'] == 0){
////            return error($res['msg']);
////        }
//        // 处理密码
////        $randStr = cmf_random_string();
////        $newPassword = md5($data['password'].$randStr);
////        $data['salt'] = $randStr;
////        $data['password'] = $newPassword;
////        $data['status'] = 0;
//        $reg = BannerModel::create($data);
//        if ($reg) {
//            $this->success('添加成功');
//        } else {
//            $this->error('添加失败');
//        }
//    }
//
//    public function update(Request $request)
//    {
//        $date = input('post.');
////        //验证数据
////        $validate = new MenuValidate();
////        $result = $validate->scene('edit')->check($date);
////        if (!$result) {
////            return error($validate->getError());
////        }
//        $user = BannerModel::where('id',$date['id'])->find();
//        if(!$user){
//            $this->error('该账号未拥有');
//        }
//
//        /*$r = checkSmsCode($date['mobile'],$date['code']);
//        if(!$r){
//            return error('验证码验证失败');
//        }*/
////        $randStr = createRandStr();
////        $password = md5($date['password'].$randStr);
////        $date['password'] = $password;
////        $date['salt'] = $randStr;
//        $user->image = $date['image'];
//        $user->url = $date['url'];
////        $user->pid = $date['pid'];
////        $user->update_time = date('Y-m-d H:i:s');
//        if ($user->save()){
//            $this->success('修改成功');
//        }else{
//            $this->error('修改失败');
//        }
//    }
//    public function delete(Request $request)
//    {
//        $date = input('post.');
//        $news = BannerModel::where('image',$date['image'])->find();
//        if (!$news) {
//            $this->error('图片不存在');
//        }
//
//        if ($news->delete()) {
//            $this->success('删除成功');
//        } else {
//            $this->error('删除失败');
//        }
//    }


}